import cv2

capture = cv2.VideoCapture(0, cv2.CAP_DSHOW)
while capture.isOpened():
    retval, img = capture.read()
    if retval:
        cv2.imshow('video', img)

    key = cv2.waitKey(1)
    # 按下空格键退出
    if key == 32:
        cv2.imwrite('myVideoImage.jpg', img)
        cv2.imshow('myVideoImage',img)

capture.release()
cv2.destroyAllWindows()
